/**
 * 参数设置管理初始化
 */
var CreditCard = {
    id: "creditCardTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CreditCard.initColumn = function () {
    var columns = [
        {field: 'selectItem',visible:false},
        {title: '记录状态', field: 'status', align: 'center', valign: 'middle',formatter: function (value, row, index) {
          	 if(value=='0')
        	 {
        			return '已申请,待审核';
        	 }else if(value=='1')
        	 {
        			return '已审核,待激活';
        	 }else  if(value=='2')
        	 {
        		 return '已激活';
        	 }else if(value=='3')
        	 {
        		 return '审核失败';
        	 }else
        	 {
        	     return '';	 
        	 }
        	 }
          	 },
        {title: '用户账号', field: 'phone', align: 'center', valign: 'middle'},
        {title: '姓名', field: 'customer_name', align: 'center', valign: 'middle'},
        {title: '上级推荐码', field: 'refer_reg_code', align: 'center', valign: 'middle'},
        {title: '卡片状态', field: 'card_status', align: 'center', valign: 'middle',sortable : true,formatter: function (value, row, index) {
       	 if(value=='0')
    	 {
    			return '待激活';
    	 }else if(value=='1')
    	 {
    			return '正常';
    	 }else  if(value=='2')
    	 {
    		 return '销卡';
    	 }else
    	 {
    		 return '';
    	 }
    
    }},
        {title: '是否新户', field: 'is_new', align: 'center', valign: 'middle',formatter: function (value, row, index) {
          	 if(value=='0')
        	 {
        			return '否';
        	 }else if(value=='1')
        	 {
        			return '是';
        	 }else
        	 {
        		 return '';
        	 }
        
        }},
        {title: '是否活户', field: 'is_active', align: 'center', valign: 'middle',formatter: function (value, row, index) {
          	 if(value=='0')
        	 {
        			return '否';
        	 }else if(value=='1')
        	 {
        			return '是';
        	 }else
        	 {
        		 return '';
        	 }
        
        }},
        {title: '进件日期', field: 'add_time', align: 'center', valign: 'middle',sortable : true},
        {title: '核卡日期', field: 'examine_time', align: 'center', valign: 'middle',sortable : true},
        {title: '激活日期', field: 'activation_time', align: 'center', valign: 'middle',sortable : true},
        {title: '首刷日期', field: 'consume_time', align: 'center', valign: 'middle',sortable : true},
        {title: '最近更新时间', field: 'update_time', align: 'center', valign: 'middle',sortable : true}
    ]
    return columns;
};



CreditCard.search = function () {
    var queryData = {};
    queryData['phone'] = $("#phone").val();
    queryData['customer_name'] = $("#customer_name").val();
    queryData['status'] = $("#status").find("option:selected").val();
    queryData['card_status'] = $("#card_status").find("option:selected").val();
    queryData['refer_reg_code'] = $("#refer_reg_code").val();
    queryData['start_time'] = $("#start_time").val().replace("/","-");
    if($("#start_time").val() != "") {
        if($("#end_time").val() == "") {
            Feng.info("请选择结束时间！");
            return false;
        }else{
            queryData['end_time'] = $("#end_time").val().replace("/","-");
        }
    }
    CreditCard.table.refresh({query: queryData});
};


CreditCard.excel = function () {
    var index = layer.open({
        type: 2,
        title: '导入信用卡记录',
        area: ['750px', '650px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/creditCard/excelList'
    });
    this.layerIndex = index;
};


$(function () {
    $("#start_time").attr('type','date');
    $("#end_time").attr('type','date');
    var defaultColunms = CreditCard.initColumn();
    var table = new BSTable(CreditCard.id, "/creditCard/list", defaultColunms);
    table.setPaginationType("server");
    CreditCard.table = table.init();
});



